<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka 消息传递机制深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: rgba(102, 126, 234, 0.3);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 15px;
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .process-step {
            position: relative;
            padding-left: 40px;
            margin-bottom: 30px;
        }
        
        .process-step::before {
            content: attr(data-step);
            position: absolute;
            left: 0;
            top: 0;
            width: 30px;
            height: 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 14px;
        }
        
        .mermaid {
            background: white;
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .component-card {
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
        }
        
        .component-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.1);
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 700;
        }
        
        .floating-shape {
            position: absolute;
            border-radius: 50%;
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            animation: float 6s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 relative overflow-hidden">
        <div class="floating-shape w-32 h-32 top-10 right-10"></div>
        <div class="floating-shape w-24 h-24 bottom-10 left-20" style="animation-delay: 2s;"></div>
        <div class="container mx-auto px-6 relative z-10">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    <i class="fas fa-network-wired mr-4"></i>
                    Kafka 消息传递机制
                </h1>
                <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                    深入解析 Apache Kafka 的核心组件与消息流转原理，<br>
                    探索高性能分布式消息系统的架构精髓
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- 消息传递流程 -->
        <div class="mb-16">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                消息传递流程全景
            </h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
                <div class="mermaid">
                    graph LR
                        A[<i class='fas fa-industry'></i> 生产者] -->|发送消息| B[<i class='fas fa-server'></i> Kafka Broker]
                        B --> C[<i class='fas fa-folder'></i> Topic]
                        C --> D[<i class='fas fa-th'></i> Partition 1]
                        C --> E[<i class='fas fa-th'></i> Partition 2]
                        C --> F[<i class='fas fa-th'></i> Partition N]
                        D --> G[<i class='fas fa-users'></i> 消费者组]
                        E --> G
                        F --> G
                        G --> H[<i class='fas fa-user'></i> 消费者 1]
                        G --> I[<i class='fas fa-user'></i> 消费者 2]
                        G --> J[<i class='fas fa-user'></i> 消费者 N]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                        style G fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>

            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="process-step" data-step="1">
                    <h3 class="font-bold text-lg mb-2">消息发送</h3>
                    <p class="text-gray-600">生产者将消息发送到指定的Topic，Kafka根据分区策略决定消息的存储位置。</p>
                </div>
                <div class="process-step" data-step="2">
                    <h3 class="font-bold text-lg mb-2">消息存储</h3>
                    <p class="text-gray-600">Broker接收消息后，根据Topic和Partition配置，将消息持久化到相应的分区中。</p>
                </div>
                <div class="process-step" data-step="3">
                    <h3 class="font-bold text-lg mb-2">消息订阅</h3>
                    <p class="text-gray-600">消费者从指定Topic订阅消息，消费者组协调分配不同分区的消费任务。</p>
                </div>
                <div class="process-step" data-step="4">
                    <h3 class="font-bold text-lg mb-2">偏移量管理</h3>
                    <p class="text-gray-600">每个消费者维护自己的Offset，记录已消费的消息位置，确保消息顺序性。</p>
                </div>
                <div class="process-step" data-step="5">
                    <h3 class="font-bold text-lg mb-2">提交确认</h3>
                    <p class="text-gray-600">消费者定期向Kafka提交Offset位置，确保消息消费状态的持久化。</p>
                </div>
            </div>
        </div>

        <!-- 核心组件详解 -->
        <div class="mb-16">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                核心组件深度剖析
            </h2>

            <!-- Producer -->
            <div class="component-card mb-8">
                <div class="flex items-start">
                    <div class="feature-icon mr-6">
                        <i class="fas fa-paper-plane"></i>
                    </div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 highlight-text">Producer 生产者</h3>
                        <p class="text-gray-600 mb-6 leading-relaxed">
                            Producer是Kafka生态系统的数据源头，负责将各种来源的数据转化为消息并发送到Kafka集群。它不仅是简单的数据发送者，更是确保数据可靠传输的第一道防线。
                        </p>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-rocket mr-2"></i>消息发送</h4>
                                <p class="text-sm text-gray-600">负责将消息发送到指定Topic，支持同步和异步发送模式。</p>
                            </div>
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-shield-alt mr-2"></i>可靠性保证</h4>
                                <p class="text-sm text-gray-600">通过ACK机制、重试策略确保消息的可靠传递。</p>
                            </div>
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-route mr-2"></i>分区路由</h4>
                                <p class="text-sm text-gray-600">根据消息Key或自定义策略决定消息的目标分区。</p>
                            </div>
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-compress mr-2"></i>数据压缩</h4>
                                <p class="text-sm text-gray-600">支持多种压缩算法，减少网络传输和存储开销。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Broker -->
            <div class="component-card mb-8">
                <div class="flex items-start">
                    <div class="feature-icon mr-6">
                        <i class="fas fa-server"></i>
                    </div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 highlight-text">Broker 服务节点</h3>
                        <p class="text-gray-600 mb-6 leading-relaxed">
                            Broker是Kafka集群的核心节点，承担着消息存储、转发、管理等关键职责。每个Broker都是一个独立的服务进程，多个Broker协同工作构成高可用的Kafka集群。
                        </p>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-database mr-2"></i>消息存储</h4>
                                <p class="text-sm text-gray-600">将消息持久化到磁盘，支持高效的顺序读写操作。</p>
                            </div>
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-copy mr-2"></i>副本管理</h4>
                                <p class="text-sm text-gray-600">管理分区副本的创建、同步和故障转移。</p>
                            </div>
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-sitemap mr-2"></i>集群协调</h4>
                                <p class="text-sm text-gray-600">参与集群元数据管理和Leader选举过程。</p>
                            </div>
                            <div class="card-hover p-4 rounded-lg">
                                <h4 class="font-bold text-purple-700 mb-2"><i class="fas fa-exchange-alt mr-2"></i>请求处理</h4>
                                <p class="text-sm text-gray-600">处